<?php /* Smarty version 2.6.20, created on 2013-05-25 01:50:46
         compiled from _core/_include/module/_mvc/control/handledialoghistory.tpl */ ?>
<?php require_once(SMARTY_CORE_DIR . 'core.load_plugins.php');
smarty_core_load_plugins(array('plugins' => array(array('modifier', 'escape', '_core/_include/module/_mvc/control/handledialoghistory.tpl', 185, false),)), $this); ?>
function HandleDialogHistory(gui, item, options) {
  this._gui = gui;
  this._item = item;
  this._options = options;
  this._popupBox = new PopupBox();
  this._popupBox2 = new PopupBox2();
  
  this._user = (options && options.user) ? options.user : null;
  this._date = (options && options.date) ? options.date : null;
  this._transitions = (options && options.transitions) ? options.transitions : null;
  this._callbackFunc = (options && options.callbackFunc) ? options.callbackFunc : function() {};
  this._isPur = (options && options.isPur) ? options.isPur : false;

  this._createElements();
};

HandleDialogHistory.prototype._createElements = function() {
  tr = this._gui.main.insertRow(-1);
  td = tr.insertCell(-1);
  td.style.height = '30px';
  td.colSpan = 4;
  td.appendChild(DOMUtils.getLoadingImage());

  this._loadData();
};

HandleDialogHistory.prototype._loadData = function() {
  this._produce = null;
  this._retrieveProduce();
};

HandleDialogHistory.prototype._verifyData = function() {
  if (this._produce) {
    this._updateElements();
  }
};

HandleDialogHistory.prototype._retrieveProduce = function() {
  var _self = this;
  if (!this._isPur) {
    var joins = '&events=1' + '&tracks=1';
    var args = '&c=d.e_oid=' + this._item.id + joins;
    new RequestUtils()._mysql('produce', args, function(result, params) { _self._produce = result.data[0];
                                                                          _self._parameters = result;
                                                                          _self._verifyData.call(_self);
                                                                        }, { php: Constant.FACTORY + '/customphp/produceread.php'});
  } else {
    this._produce = Produce.instance();
    this._produce.v2_events = [];
    this._produce.v2_tracks = [];
    this._updateElements();
  }
};

HandleDialogHistory.prototype._updateElements = function() {
  var valid, track, a, _self = this;
  DOMUtils.removeTableRows(this._gui.main, 1);
  DOMUtils.removeChildElements(this._gui.reverse);
  
  MiscUtils.sort(this._produce.v2_events, ['id']);
  MiscUtils.sort(this._produce.v2_tracks, ['id']);
  track = (this._produce.v2_tracks.length > 0) ? this._produce.v2_tracks[this._produce.v2_tracks.length - 1] : null
  
  if (this._produce.v2_events.length == 0) {
    tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.colSpan = 4;
    td.style.height = '20px';
    td.style.backgroundColor = '#ebebe3';
    td.style.borderLeft = 'solid 1px #b4b4b4';
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.style.textAlign = 'center';
    td.appendChild(document.createTextNode('N/A'));
  }

  for (var i = 0, il = this._produce.v2_events.length; i < il; i++) {
    var event = this._produce.v2_events[this._produce.v2_events.length - 1 - i];

    var tr = this._gui.main.insertRow(-1);
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.style.height = '25px';
    td.style.textAlign = 'center';
    td.style.verticalAlign = 'middle';
    td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
    td.appendChild(document.createTextNode(SimpleDate.format(event.date)));
    td = tr.insertCell(-1);
    td.style.borderRight = 'solid 1px #b4b4b4';
    td.style.borderBottom = 'solid 1px #b4b4b4';
    td.style.height = '25px';
    td.style.textAlign = 'left';
    td.style.paddingLeft = '15px';
    td.style.verticalAlign = 'middle';
    td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
    td.appendChild(document.createTextNode(event.userAccount));
    var str = DlmanageUtils.text(Manage.map(), this._item.pi_model, event.sourceId, event.targetId, '');
    if (str != '') {
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(str));
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.extra + ((event.extra && event.overdueReason) ? ' / ' : '') + ((event.overdueReason) ? 'Overdue Reason: ' + event.overdueReason : '')));
    } else {
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.verticalAlign = 'middle';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
      td.appendChild(document.createTextNode(event.extra + ((event.extra && event.overdueReason) ? ' / ' : '') + ((event.overdueReason) ? 'Overdue Reason: ' + event.overdueReason : '')));
      td = tr.insertCell(-1);
      td.style.borderRight = 'solid 1px #b4b4b4';
      td.style.borderBottom = 'solid 1px #b4b4b4';
      td.style.height = '25px';
      td.style.verticalAlign = 'middle';
      td.style.textAlign = 'left';
      td.style.paddingLeft = '15px';
      td.style.backgroundColor = (i % 2 != 0) ? '#ecece4' : '#f5f5ec';
    }
  }
  
  valid = false;
  if (track) {
    for (var i = 0, il = this._transitions.length; i < il; i++) {
      var t = this._transitions[i];
      
      if (t.validate(this._item, this._user, this._date, null)) {
        valid = true;
      }
    }
    valid = (track.userTrackId == this._user.trackId) ? true : valid;
  }

  if ((this._item.pi_model == Constant.MODEL_NAME_PRODUCT_COMMON && (this._item.state == 15 || this._item.state == 16 || this._item.state == 17)) || 
      (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_RETOUCH_MAGAZINE && (this._item.state == 15 || this._item.state == 16 || this._item.state == 17)) || 
      (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_4X6 && (this._item.state == 9 || this._item.state == 10 || this._item.state == 11)) ||
      (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_VIDEODVD && (this._item.state == 4 || this._item.state == 5 || this._item.state == 6)) ||
	  (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_VIDEODVD_BLURAY && (this._item.state == 4 || this._item.state == 5 || this._item.state == 6)) ||
      (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_SLIDESHOW && (this._item.state == 7 || this._item.state == 8 || this._item.state == 9)) ||
      (this._item.pi_model == Constant.MODEL_NAME_PRODUCT_SLIDESHOW_OL && (this._item.state == 7 || this._item.state == 8 || this._item.state == 9)) ||
      (this._item.pi_model == Constant.MODEL_NAME_USER_VIDEOGRAPHER && (this._item.state == 7 || this._item.state == 8)) ||
      this._item.pi_model == Constant.MODEL_NAME_MAIL || this._item.pi_model == Constant.MODEL_NAME_CUSTOM) {
    valid = false;
  }
  
  if (this._item.cancelled == 1) {
    valid = false;
  }
  
  if (valid) {
    this._gui.reverse.appendChild(document.createTextNode(track.userAccount + ' ' + DlmanageUtils.text(Manage.map(), this._item.pi_model, track.sourceId, track.targetId, track.extra)));
    a = document.createElement('a');
    a.href = '#';
    a.style.margin = '0 0 0 5px';
    a.appendChild(document.createTextNode('Reverse'));
    a.onclick = function() { var div, pos, func1, func2;
                             func1 = function() { if (_self._item._text == '') {
                                                    window.alert('CAN NOT BE EMPTY');
                                                    return;
                                                  }
                                                  var e = ProduceEvent.instance();
                                                  e.produce_trackId = _self._item.trackId;
                                                  e.date = _self._date;
                                                  e.userAccount = _self._user.account;
                                                  e.extra = '[R] ' + DlmanageUtils.text(Manage.map(), _self._item.pi_model, track.sourceId, track.targetId, track.extra) + '/' + _self._item._text + '';
                                                  var pUsers = [];
                                                  var produce = DlmanageUtils.reverse(_self._item, track);
                                                  if (_self._item.pi_model == '<?php echo ((is_array($_tmp=@MODEL_NAME_PRECON)) ? $this->_run_mod_handler('escape', true, $_tmp, 'javascript') : smarty_modifier_escape($_tmp, 'javascript')); ?>
') {
                                                    pUsers = DlmanageUtils.getProduceUser(_self._item, track);
                                                  }
                                                  new RequestUtils()._write2([{ n: 'produce', a: [produce], r: [] }, { n: 'produceevent', a: [e], r: [] }, { n: 'producetrack', a: [], r: [track] }, { n: 'produceuser', a: pUsers, r: _self._item.pUsers }, { n: 'producetrackuser', a: [], r: track.pUsers }], _self._callbackFunc, { php: Constant.FACTORY + '/customphp/mysqlwrite2.php', pos: pos });
                                                  _self._popupBox2._close();
                                                }
                             var func2 = function() { _self._popupBox2._close(); };
                             pos = DOMUtils.findPos(this);
                             div = document.createElement('div');
                             MiscUtils.dialog(_self._popupBox2, pos, div, func1, func2, {t: 'Reason'});
                             new DialogInput(div, _self._item, { title: '' });
                             return false;
                           };
    this._gui.reverse.appendChild(a);
  } else {
    this._gui.reverse.appendChild(document.createTextNode('Reverse is not permitted, ' + ((track) ? (track.userAccount + ' ' + DlmanageUtils.text(Manage.map(), this._item.pi_model, track.sourceId, track.targetId, track.extra)) : ' (None)')));
  }
};